package model

import (
	"qabx.net/safe-app-center/pkg/utils"
	"time"
)

type TblBlockStrategy struct {
	BlockStrategyId int `json:"block_strategy_id" xorm:"pk autoincr"`
	//AppId           int       `json:"app_id"`
	BlockType  string    `json:"block_type"`
	BlockData  string    `json:"block_data"`
	IsDel      int       `json:"is_del"`
	CreateTime time.Time `json:"create_time"`
	UpdateTime time.Time `json:"update_time"`
	AreaNo     string    `json:"area_no"`
}

func (s *TblBlockStrategy) AddBlockStrategy() (int, error) {
	dbClient, _ := utils.GetDbClient()
	//s.AppId = appId
	s.BlockType = "domain"
	s.CreateTime = time.Now()
	s.UpdateTime = time.Now()
	s.IsDel = 0
	dbClient.InsertParam = utils.InsertParam{
		Resource: s,
		Table:    "tbl_block_strategy",
	}
	_, err := dbClient.Insert()
	return s.BlockStrategyId, err

}

type TblBlockGroup struct {
	BlockGroupId    int    `json:"block_group_id" xorm:"pk autoincr"`
	BlockGroupName  string `json:"block_group_name"`
	UserId          int    `json:"user_id"`
	GatewayId       int    `json:"gateway_id"`
	DeviceId        int    `json:"device_id"`
	IsOpen          int    `json:"is_open"`
	BlockStrategyId int    `json:"block_strategy_id"`
	IsDel           int    `json:"is_del"`
	CreateTime      string `json:"create_time"`
	UpdateTime      string `json:"update_time"`
	BlockType       int    `json:"block_type"`
}

func (s *TblBlockGroup) AddBlockGroup() (int, error) {
	//s.AppId = appId
	dbClient, _ := utils.GetDbClient()
	s.CreateTime = time.Now().Format("2006-01-02 15:04:05")
	s.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
	s.IsDel = 0
	dbClient.InsertParam = utils.InsertParam{
		Resource: s,
		Table:    "tbl_block_group",
	}
	_, err := dbClient.Insert()
	return s.BlockGroupId, err

}

type TblBlockCircle struct {
	BlockGroupId int    `json:"blockGroupId"`
	CircleType   int    `json:"circle_type"`
	CircleWeek   string `json:"circle_week"`
	CircleDate   string `json:"circle_date"`
	CircleHour   string `json:"circle_hour"`
	CircleMinute string `json:"circle_minute"`
	IsDel        int    `json:"is_del"`
	CreateTime   string `json:"create_time"`
	UpdateTime   string `json:"update_time"`
}

func (s *TblBlockCircle) AddBlockCircle() error {
	//s.AppId = appId
	dbClient, _ := utils.GetDbClient()
	s.CreateTime = time.Now().Format("2006-01-02 15:04:05")
	s.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
	s.IsDel = 0
	dbClient.InsertParam = utils.InsertParam{
		Resource: s,
		Table:    "tbl_block_circle",
	}
	_, err := dbClient.Insert()
	if err != nil {
		return err
	}
	return err

}
